home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Utilities / Programming / PowerReplace 5.0 / Documentation / 2. FilterFile Doc < prev    next >
Encoding:
Text File  |  1996-06-03  |  6.9 KB  |  153 lines  |  [ttro/ttxt]

  1.  
  2. PowerReplace  •2• Filter File Documentation
  3. (version 5.0, 1996.6.3) 
  4. ________________________________________________________________________________________
  5.  
  6. PowerReplace interprets filter file line by line. A line must be as follow:
  7.     %comments-line
  8.     #define-line
  9.     first-stuff  second-stuff
  10.  
  11. Comments-line has no effect. Define-line is used to set some option. The stuff-line means that the first-stuff will be replaced by the second-stuff everywhere in the text file. For the first-stuff, you can use the format:
  12.     "first-string"     
  13.     $hex-string$ 
  14.     'pattern'    
  15.  
  16. And for the second-stuff, you can use:
  17.     "second-string"
  18.     $hex-string$    
  19.  
  20. In the next, first, we give some examples. Then we give a short description for each stuff. You can find at the end of this document some bad examples for understand better. 
  21.  
  22. Note that a good way to learn is to study the sample filter files in the “Filter” folder.
  23.  
  24. Good Examples:
  25.    "é"   "é"            % OK. for HTML
  26.    "é"          "é"     % OK. for HTML
  27.    "à"          "A"            % OK. lower to upper
  28.    "è"          "e"            % OK. 8 bit to 7 bit
  29.    "è"          "\\`e"         % OK. for TeX. \\ means the character \
  30.    "//*\r"      " "            % OK. delete C++ comments
  31.  
  32. First-String:
  33. - In the simple case, a first-string is a normal string without asterisk-sign(*). You must use meta character for give special characters in the string. 
  34. Example: "abc" and "ab\"ce" are simple-strings.
  35.  
  36. - In the more general case, a first-string may contain one asterisk-sign(*) in the middle of this string for any indeterminate substring. 
  37. For example, "abc*xyz" means all normal string beginning with "abc" and ending with "xyz". 
  38. An other example: "//*\n" means all characters after "//" of a line(C++ comments). 
  39. But either "*ab" or "a*b*c" isn’t double-string.
  40.  
  41. Second-String:
  42. - In the simple case, a second-string is a normal string without asterisk-sign(*).
  43. - In the more general case, a second-string may contain one tag \>. We’ll discuss this case later in the section “Insertion tag in the second-string.”
  44.  
  45.  
  46. Character set:
  47. We can tell PowerReplace the special characters by using meta character as:
  48.     \\    representing    \                        
  49.     \"    representing    "                    
  50.     \*    representing    *                        
  51.     \t    representing    TAB               
  52.     \n    representing    LF                       
  53.     \r    representing    CR
  54.  
  55. PowerReplace supports all character set in filter files, the control characters (0-31) in particular.  We can specify characters in filters by using ASCII numbers in decimal, hexadecimal or octal base. For example, "\d065" "\x41" "\o101" (or "\101") all means the same character "A".  Examples:
  56.     "\d65B"  "B\101\x43" % OK. change "AB" to "BAC"
  57.     "\0"     ""          % OK. strip NULL
  58.  
  59. Define(#):
  60. The default meta character used by PowerReplace is "\". You can change it. For example, to set "/" as meta character, just insert the following define-line in your filter file:
  61.     #meta       "/"
  62.  
  63. If you don't use any meta character, insert the following define-line:
  64.     #meta       ""
  65.  
  66. For example, to replace è by \\`e, we can use the following line:
  67.     "è"          "\\`e"        % OK. for TeX. \\ means the character \
  68. or the following two lines:
  69.     #meta       "/"
  70.     "è"          "\`e"         % OK. for TeX. now \ isn’t meta character!
  71.  
  72. I use the default meta character "\" in my documentation.
  73.  
  74. Hexadecimal string:
  75. The hex-string must be enclosed by dollar-sign($hex-string$). You can use one of the following lines to convert "AB" to "BAC":
  76.    "AB"      "BAC"         % OK. change "AB" to "BAC"
  77.    $6566$    $666567$      % OK. change "AB" to "BAC"
  78.    $6566$    "BAC"         % OK. change "AB" to "BAC"
  79.    "AB"      $666567$      % OK. change "AB" to "BAC"
  80.  
  81. Regular expression (pattern):
  82. This version supports Unix regular expression (pattern) for searching string. The pattern must be enclosed by single quotation marks ('pattern'). We can only use pattern for first-stuff but not for the second-stuff. Here is a small description of pattern supported by PowerReplace:
  83.  
  84. Uppercase and lowercase are always ignored. An ordinary character (not mentioned below) matches that character.
  85.  
  86. ^    matches beginning of line
  87. $    matches end of line
  88. \    quotes character after it, whether special or not
  89. .    mathches any character
  90. *    a single character followed by * matches 
  91.      zero or more occurrences of the character. 
  92.      In particular, ".*" matches an arbitrary possibly empty string.
  93. +    a single character followed by + matches 
  94.      one or more occurrences of the character. 
  95. [ ]  a set of characters in the set matches any single character in the set. 
  96.      [c1-c2] matches any character of ascii ranging from c1 to c2.
  97.      [^set] matches any character not in set. 
  98. See also any Unix book for more information about pattern. Example:
  99.    '^ +'    ""  % OK. strip spaces at beginning of line.
  100.  
  101. Insertion tag in the second-string:
  102. In the second-string, you can use a new tag \> for inserting a substring of the first-string-found (called “source”). We use two parameters (x,y) to define this substring: It takes x letters at the beginning and y letters at the ending of the source. By default, if (x,y) are missing, this substring is just the source. 
  103. Example1: My text is "hello". If the first-string is "e*o", then the source will be "ello". We study the following filter lines:
  104.   (1) "e*o"   "\> and goodbye"
  105.   (2) "e*o"   "\> and goodbye" (all, 0)
  106.   (3) "e*o"   "\> and goodbye" (0, all)
  107.   (4) "e*o"   "\> and goodbye" (all, all)
  108.   (5) "e*o"   "\> and goodbye" (0, 0)
  109.   (6) "e*o"   "\> and goodbye" (1, 0)
  110.   (7) "e*o"   "\> and goodbye" (0, 2)
  111.   (8) "e*o"   "\> and goodbye" (1, 1)
  112. then, the output file contains the following text for each case:
  113.   (1,2,3)  "hello and goodbye"
  114.   (4) "helloello and goodbye"
  115.   (5) "h and goodbye"
  116.   (6) "he and goodbye"
  117.   (7) "hlo and goodbye"
  118.   (8) "heo and goodbye"
  119.  
  120. Example2: We want to change "à" to "a'" if and only if it is the last letter of a word. The solution whitout the insertion tag is writing the following lines:
  121.   "à,"     "a',"
  122.   "à;"     "a';"
  123.   "à:"     "a':"
  124.   "à."     "a'."
  125.   "à!"     "a'!"
  126.   "à?"     "a'?"
  127.   "à "     "a' "
  128. With the insert tag, you need only the following line:
  129.   "à[,;:\.!? ]"     "a'\>"    (0,1)
  130. Or this line:
  131.   "à[^a-zA-Z]"      "a'\>"    (0,1)
  132.  
  133. Bad Examples:
  134.    '^ +'       'abc'    % BAD. pattern at the second position 
  135.    $A9876$     ""       % BAD. bad hex-string, length odd
  136.    "a*b*c"     "\xB3"   % BAD. two * in the first-string, try "a*b\*c" "\xB3"
  137.    '[aeiou'    " "      % BAD. pattern syntax error
  138.    "a"a"       "AA"     % BAD. syntax error. try "a\"a" "AA"
  139.    "\da"       "a"      % BAD. decimal number error
  140.    $23"        "98"     % BAD. syntax error. try  $23$ "98" 
  141.    $A567BDG$   "98"     % BAD. bad hex-string
  142.    "toto"      "t*t"    % BAD. bad second-string, try "toto" "t\*t"
  143.  
  144.  
  145.  
  146.  
  147.  
  148. _________________________
  149. Guoniu Han
  150. email: guoniu@math.u-strasbg.fr
  151. http://130.79.4.26/~guoniu/mac/
  152. _________________________
  153.